package com.zzl.car.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzl.car.entity.CarCheckRecord;
import com.zzl.car.entity.CarDetailInfo;
import com.zzl.car.exception.ZdpException;
import com.zzl.car.mapper.ZzwCarCheckRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ZzwCarCheckRecordService {

    @Autowired
    private ZzwCarCheckRecordMapper carCheckRecordMapper;

    /*
     * 将字符串转为 字符串数组
     */
    public PageInfo<CarCheckRecord> getCarCheckRecord(Integer state, int currentPage){
        PageInfo<CarCheckRecord> pageInfo = null;

        PageHelper.startPage(currentPage,6);
        List<CarCheckRecord> carCheckRecord=carCheckRecordMapper.getCarCheckRecord(state);
        for (int i = 0; i < carCheckRecord.size(); i++) {
            CarCheckRecord c = carCheckRecord.get(i);
            c.setCarDoors(c.getDoors().split(";"));
            c.setCarWindows(c.getWindows().split(";"));
            c.setCarBumpers(c.getBumper().split(";"));
        }

        pageInfo = new PageInfo<>(carCheckRecord);
        pageInfo.setList(carCheckRecord);
        return pageInfo;
    }

    public String deleteCarCheckRecord(Integer id){
        if(carCheckRecordMapper.deleteCarCheckRecord(id) > 0)
            return "1";
        else
            throw new ZdpException(1111,"删除失败");
    }
}
